package com.kehao.leetcode.algorithm;


import java.util.HashSet;
import java.util.List;

//https://leetcode-cn.com/problems/word-break/
public class Solution139 {
    public boolean wordBreak(String s, List<String> wordDict) {
        HashSet set = new HashSet(wordDict);
        boolean[] dp = new boolean[s.length()+1];
        dp[0] = true;
        for (int i = 1; i < s.length()+1; i++) {
            for (int j = 0; j <i; j++) {
                if(dp[j] && set.contains(s.substring(j,i))){
                    dp[i] = true;
                    break;
                }
            }
        }
        return dp[s.length()];
    }
}
